import { getGoodsDetail } from "../../api"

const state = {
    goodsDetailListInfo: {} //商品详情信息
}
const actions = {
    async reqgetGoodsDetailListInfo({ commit }, skuId) {
        /* 发送ajax请求拿到响应数据 */
        const result = await getGoodsDetail(skuId);
        /* 将响应数据提交给mutations来操作 */
        if (result.code === 200) commit("RECEIVE_GOODSDETAILLISTINFO", result.data)
    }
}
const mutations = {
    /* 将actions传过来的数据存储到vuex中 */
    RECEIVE_GOODSDETAILLISTINFO(state, reqValue) {
        state.goodsDetailListInfo = reqValue
    }
}
const getters = {
    /* 参数中接收的是state中的所有数据 */
    categoryView(state) {
        return state.goodsDetailListInfo.categoryView || {}
    },
    skuInfo(state) {
        return state.goodsDetailListInfo.skuInfo || {}
    },
    /* 销售属性  (版本 颜色 容量...) */
    spuSaleAttrList(state) {
        return state.goodsDetailListInfo.spuSaleAttrList || []
    }
}
export default {
    state,
    actions,
    mutations,
    getters
}



